(function() {
  define(['chaplin', 'lib/feedback', 'lib/enums'], function(Chaplin, Feedback, Enums) {
    var ajaxSetup;
    return ajaxSetup = {
      error: function(error, ajaxOptions, thrownError) {
        var e, errorMessage, noExcepMessages;
        noExcepMessages = ['usuario.inativo', 'usuario.termo.invalido'];
        if (error.responseJSON && error.responseJSON.message) {
          errorMessage = error.responseJSON.message;
        } else {
          try {
            errorMessage = JSON.parse(error.responseText).message;
          } catch (_error) {
            e = _error;
            errorMessage = error.responseText;
          }
        }
        if (!errorMessage) {
          errorMessage = 'Um erro inexperado aconteceu. Tente novamente em alguns minutos.';
        }
        if (error.status === 401) {
          window.location.hash = '#login';
        }
        if (_.indexOf(noExcepMessages, errorMessage) < 0 && error.status !== 200 && error.status !== 401) {
          return Chaplin.EventBroker.publishEvent('feedback:error', Enums.messages[errorMessage] || errorMessage);
        }
      }
    };
  });

}).call(this);
